package cn.lg.soar.core.util.easyexcel.model;

import lombok.Getter;
import lombok.Setter;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.util.CellRangeAddress;

/**
 * 单元格属性
 * @author luguoxiang
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@Getter
@Setter
public class MergeCellInfo extends CellInfo{

    /**
     * 合并行数
     */
    private int rowMergeCount;

    /**
     * 合并列数
     */
    private int colMergeCount;

    public MergeCellInfo(int rowIndex, int colIndex) {
        super(rowIndex, colIndex);
        this.rowMergeCount = 1;
        this.colMergeCount = 1;
    }

    public MergeCellInfo(int rowIndex, int colIndex, Object value) {
        super(rowIndex, colIndex, value);
        this.rowMergeCount = 1;
        this.colMergeCount = 1;
    }

    public MergeCellInfo(int rowIndex, int colIndex, Object value, CellStyle style) {
        super(rowIndex, colIndex, value, style);
        this.rowMergeCount = 1;
        this.colMergeCount = 1;
    }

    public MergeCellInfo(int rowIndex, int colIndex, int rowMergeCount, int colMergeCount) {
        super(rowIndex, colIndex);
        this.rowMergeCount = rowMergeCount;
        this.colMergeCount = colMergeCount;
    }

    /**
     * 增加行合并数
     * @return
     */
    public int addRowMergeCount() {
        return ++rowMergeCount;
    }

    /**
     * 增加列合并数
     * @return
     */
    public int addColMergeCount() {
        return ++colMergeCount;
    }

    /**
     * 是否需要合并
     * @return
     */
    public boolean isMerge() {
        return rowMergeCount > 1 || colMergeCount > 1;
    }

    /**
     * 获取单元格合并地址
     * @return
     */
    public CellRangeAddress getCellRangeAddress() {
        return new CellRangeAddress(
                rowIndex,
                rowIndex + rowMergeCount - 1,
                colIndex,
                colIndex + colMergeCount - 1
        );
    }
}
